home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12319 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.0 KB

  1. Path: news.interpath.net!usenet
  2. From: "Richard F. Albury" <richard.albury@virtus.com>
  3. Newsgroups: comp.lang.c++,comp.lang.pascal.delphi.misc
  4. Subject: Re: Calling all API experts !!
  5. Date: Tue, 19 Mar 1996 09:33:20 -0500
  6. Organization: Virtus Corporation
  7. Message-ID: <314EC5B0.7C0C@virtus.com>
  8. References: <DoIMG1.F9y@unx.sas.com>
  9. NNTP-Posting-Host: albury-win.virtus.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. sdkkah@mvs.sas.com wrote:
  16. > I am trying to make an application with a tool which just recently allowed
  17. > calling Windows API's. The tool (The SAS System) itself is written in C++.
  18. > Some API's works OK, but there's one I cant figure out how to use right.
  19. > Its called GetProfileString. I need to access the [fonts] section of WIN.INI,
  20. > and get all entries and values. But I dont know the number of entries to
  21. > read, since this obviously varies. Is there some kind of trick that would
  22. > allow me to loop through untill the last entry is read, without having to
  23. > know the exact number of entries in each section ?
  24. > Getting the font names is just getting me half the way. I also need to
  25. > know the point size and property (Bold,Italic etc..). Does anyone know
  26. > where I can get this information ?
  27. > Finally, can anyone recommend any good documentations as to how
  28. > Windows API's are dealt with in general ?
  29.  
  30. The following function will let you read all the keys for a section.  Once you
  31. have the keys, you can easily get the values.  As for documentation on the
  32. Windows API, the SDK manuals (also available as online help for most development
  33. systems) and "Programming Windows" by Charles Petzold (on the MSDN CD-ROM and
  34. recently updated for Windows 95) are your two best bets.  Hope this helps.
  35.  
  36. const DWORD INITIAL_BUFFER_SIZE   = 512;
  37. const DWORD BUFFER_GROW_INCREMENT = 32;
  38.  
  39. int                 // number of keys found in this section
  40. EnumerateKeys(
  41. LPCSTR sectionName) // section name, i.e., "fonts"
  42. {
  43.     int nKeys = 0;
  44.  
  45.     DWORD dwChars = INITIAL_BUFFER_SIZE;
  46.  
  47.     LPSTR buffer = new char[dwChars];
  48.  
  49.     DWORD dwCharsRead = GetProfileString(sectionName,
  50.                                          NULL,
  51.                                          "",
  52.                                          buffer,
  53.                                          dwChars);
  54.     while ( dwCharsRead >= (dwChars - 2) )
  55.     {
  56.         delete [] buffer;
  57.         dwChars += BUFFER_GROW_INCREMENT;
  58.         buffer = new char[dwChars];
  59.         dwCharsRead = GetProfileString(sectionName,
  60.                                        NULL,
  61.                                        "",
  62.                                        buffer,
  63.                                        dwChars);
  64.     }
  65.  
  66.     if ( dwCharsRead )
  67.     {
  68.         LPCSTR key = buffer;
  69.         while ( *key )
  70.         {
  71. #ifdef _DEBUG
  72.             OutputDebugString(key);
  73.             OutputDebugString("\r\n");
  74. #endif // _DEBUG
  75.             ++nKeys;
  76.             key += lstrlen(key) + 1;
  77.         }
  78.     }
  79.  
  80.     delete [] buffer;
  81.  
  82.     return nKeys;
  83. }
  84.